import * as types from "../types/suggestTypes";

const initialState = {
  loading: false,
  error: undefined,
  success: false,
  title: "",
  content: "",
};

export default function suggestReducer(state = initialState, action) {
  switch (action.type) {
    case types.SUGGEST_LOADING:
      return {
        ...state,
        loading: true,
      };
    case types.SUGGEST_DONE:
      return {
        ...state,
        loading: false,
        success: true,
      };
    case types.SUGGEST_ERROR:
      return {
        ...state,
        loading: false,
        error: action.error,
      };
    case types.SUGGEST_EDIT_TITLE:
      return {
        ...state,
        title: action.title,
      };
    case types.SUGGEST_EDIT_CONTENT:
      return {
        ...state,
        content: action.content,
      };
    case types.SUGGEST_UNMOUNT:
      return {
        ...initialState,
      };
    default:
      return state;
  }
}
